package org.aplombh.java.leetcode.dailyTopic;

import java.util.TreeSet;

public class _1684统计一致字符串的数目 {
}

class Solution1684_1 {
    public int countConsistentStrings(String allowed, String[] words) {
        TreeSet<Character> all = new TreeSet<>();

        int ans = 0;

        for (char c : allowed.toCharArray()) {
            all.add(c);
        }


        for (String word : words) {
            boolean flag = true;
            char[] chars = word.toCharArray();
            for (char aChar : chars) {
                if (!all.contains(aChar)) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                ans++;
        }
        return ans;
    }
}

class Solution1684_2 {
    public int countConsistentStrings(String allowed, String[] words) {
        boolean[] chs = new boolean[26 + 1];
        int ans = 0;

        for (char c : allowed.toCharArray()) {
            chs[c - 'a'] = true;
        }

        for (String word : words) {
            for (char c : word.toCharArray()) {
                if (!chs[c - 'a']) {
                    ans--;
                    break;
                }
            }
            ans++;
        }
        return ans;
    }
}